import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;

/**
 * @Title: one
 * @Author kerry
 * @Package PACKAGE_NAME
 * @Date 2024/11/16 21:48
 */

public class One {
    public static void main(String[] args) {
        // 类文件 驼峰命名 -  大写字母开头

        // 编译以后得到类字节码文件 class
        System.out.println("hello world");
        System.out.println();
        System.out.println("上面是空行");

        System.out.printf("不换行 接在后面的");
        // 注释 - 单行

        /**
         * 多行注释
         */

        // 8大基本数据类型

        byte a = 10; // -128 ~ 127  8位

        short b = 10;

        int c = 10;

        long d = 10;

        float f = 4.0f;

        double dd = 10;

        boolean bool = true;

        char ch = 'a'; // 字符类型

        /**
         * 超出范围 补位：
         * cc = 128  aa = -128 ,cc = 129 aa =-127 ,cc = 130 aa = -126, 超出byte 范围 向前补位
         * cc = -129 aa = 127, cc = -130, aa = 126
         *
         */
        int cc = 130;
        byte aa = (byte) cc;
        System.out.println(aa);

        System.out.println(Byte.toUnsignedInt(aa));

        // 浮点数计算问题：2.0 -1.0  = 0.899999
        // 原因：浮点数采用二进制表示，二进制系统中无法精确地表示分数 1/10,像10进制无法表示 1/3 一样道理


        // boolean 类型不能与整型转换


        double x = 9.997;
    int xx = (int)x;// 强制类型转换
        System.out.println(xx);
        System.out.println(Math.round(x));

        int aaa = 10;
    aaa += 5;

        System.out.println("括号级别运算的优先级");

        int x1 = (int) (Math.random() * 10) + 1;


        int x2 = (int) (Math.random() * 10) + 1;

        int x3 = (int) (Math.random() * 10) + 1;

        boolean b1 = true;
        boolean b2 = true;
        boolean b3 = false;
        System.out.println(b1);
        System.out.println(b2);
        if (b1 && b2 || b3) {
            System.out.println("真");
        } else {
            System.out.println("假的");
        }

        String s = "hello";
        s.substring(0,3);

        // 用一个界定符分隔
        String all = String.join(" / ","S","M","L","XL");
        System.out.println(all);

        // 不区分大小写 比较字符串是否相等

        if ("Hello".equalsIgnoreCase("hello")) {
            System.out.println("不区分大小写");
        } else {
            System.out.println("---");
        }
        char[] ccc = {'h','l','l','e','o'};
        String s1 = new String(ccc);
        System.out.println(s1);

        String s11 = new String(ccc,0,2);
        System.out.println(s11);

        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("L");
        stringBuilder.append("O");
        stringBuilder.append("V");
        stringBuilder.append("E");
        stringBuilder.append("java");
        System.out.println(stringBuilder.toString());
        System.out.println("===格式化输出==");

        System.out.printf("hello %s, age %d","ymb",10);
        int jj = 20;
        {
            System.out.println("===block==");
            int k  = 10;
            System.out.println(k);
            System.out.println(jj);
            jj+=4;
        }
        System.out.println(jj);
        //System.out.println(k); 不能使用
        test();

        // 大数

        BigInteger bigInteger = BigInteger.valueOf(100);
        BigInteger add = bigInteger.add(BigInteger.valueOf(100));
        BigInteger multiply = add.multiply(BigInteger.valueOf(3));
        System.out.println(add);
        System.out.println(multiply);

        BigDecimal bigDecimal = BigDecimal.valueOf(100);
        System.out.println("===数组===");
        arr();
        // 数组拷贝
        arrCopy();
        s();// 抽奖案例

        more();// 多维数组
    }


    public static void test() {
        // 循环
        int i;
        for (i = 0; i < 10; i++) {
        }
        System.out.println("=====");
        System.out.println(i);
    }

    public static void arr() {
        // 创建数组的方式
        int[] a = new int[10];
        for (int i = 0; i < a.length; i++) {
            System.out.println(a[i]);
        }
        int[] aa = {1,2,3,4,5};
        // for each 循环
        System.out.println(Arrays.toString(aa));
        for (int i : aa) {
            System.out.println(i);
        }
    }

    public static void arrCopy() {
        // 数组拷贝
        int[] luckNumber = {1,2,3,4,5,6};

        int[] smallPrimes = luckNumber;// luckNumber 和  smallPrimes 两个变量将引用同一个数组。
        luckNumber[2] = 10;
        System.out.println(Arrays.toString(luckNumber));
        System.out.println(smallPrimes[2]); // 10



        // 创建新数组方式
        int[] copyLuckNumber = Arrays.copyOf(luckNumber,luckNumber.length);// 创建新的数组
        luckNumber[3] = 20;
        System.out.println(Arrays.toString(luckNumber));
        System.out.println(copyLuckNumber[3]);// 4
    }

    public static void s() {
        // 数组排序 - 抽奖案例

        // 1. 设置号码数量，抽中数量
        int n = 100;
        int k = 6;

        // 2. 把号码依次存入数组中
        int[] number = new int[n];
        for (int i = 0; i < n; i++) {
            number[i] = i+1;
        }

        // 3. 抽中号码存放数组
        int[] result = new int[k];

        // 4. 开始抽奖
        for (int i = 0; i < result.length; i++) {
            // 获取中奖随机号码
            int r =  (int)(Math.random() * n);// 0~n 随机数

            // 存放
            result[i] = number[r];

            // 保证不能再次抽中该号码
            number[r] = number[n-1];// 把抽中号码的替换最后一个号码

            n--;// 缩小随机数范围
        }

        Arrays.sort(result);
        System.out.println(Arrays.toString(result));

    }

    public static void more() {
        // 多维数组操作
        int[][] a ={
                {1,2,3},
                {3,4,5,6},
                {7,8,9,10,11},
                {12,13,14,15,16}
        };
        System.out.println(Arrays.deepToString(a));
    }
}



// 枚举类型
enum Size{
    SMALL(1,"小码"),MEDIUM(2,"中码"),LANGE(2,"大码"),EXTRA_LANGE(3,"超大码");
    Size(int i, String s) {
    }
}